package io.renren.modules.neo4j.respository;

import io.renren.modules.neo4j.entity.node.course;
import io.renren.modules.neo4j.entity.node.knowledge;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface KnowledgeRespository extends Neo4jRepository<knowledge,Long> {


    @Query("create (k:knowledge{name:{endName}}) with k  match (c:course{name:{startName}})  create(c)-[:contain]->(k)")
    void saveKnowledgeInCourse(@Param("startName") String startName,@Param("endName") String endName);
    @Query("match (c:course{name:{startName}}) with c match (k:knowledge{name:{endName}})  match(c)-[r]-(k) delete k,r  ")
    void delKnowledgeInCourse(@Param("startName") String startName,@Param("endName") String endName);
    @Query("match (c:knowledge{name:{startName}}) with c match (k:knowledge{name:{endName}})  create(c)-[:progressively]->(k)")
    void saveOneCourseKnowledgeShip(@Param("startName") String startName,@Param("endName") String endName);
    @Query("match (c:knowledge{name:{startName}}) with c match (k:knowledge{name:{endName}})  create(c)-[:outProgressively]->(k)")
    void saveNoOneCourseKnowledgeShip(@Param("startName") String startName,@Param("endName") String endName);
    @Query("match (c:knowledge{name:{startName}}) with c match (k:knowledge{name:{endName}})  match(c)-[r]->(k) delete r")
    void delCourseKnowledgeShip(@Param("startName") String startName,@Param("endName") String endName);
    /*
    @Query("match (c:knowledge{name:{startName}}) with c match (k:knowledge{name:{endName}})  match(c)-[r]->(k) delete r")
    void delNoOneCourseKnowledgeShip(String startName, String endName);*/


    @Query("match (c:knowledge{name:{startName}}) with c  create (k:material{name:{endName},index:{index},path:{path},type:{type}})  create (c) -[ct:learn]-> (k)return c,ct,k")
    void saveLearnInKnowledge(@Param("path") String path,@Param("type") int type,@Param("index") int index,@Param("startName") String startName,@Param("endName") String endName);
    @Query("match (c:knowledge{name:{startName}}) with c match (k:material{name:{endName}})  match(c)-[r]-(k) delete k,r  ")
    void delLearnInKnowledge(@Param("startName") String startName,@Param("endName") String endName);
    @Query("match (c:material{name:{startName}}) with c match (k:material{name:{endName}})  create(c)-[:progressively]->(k)")
    void saveLearnShip(@Param("startName") String startName,@Param("endName") String endName);
    @Query("match (c:material{name:{startName}}) with c match (k:material{name:{endName}})  match(c)-[r]->(k) delete r")
    void delLearnShip(@Param("startName") String startName,@Param("endName") String endName);
    @Query("match (c:material{name:{startName}}) with c match (k:material{name:{endName}})  create(c)-[:outProgressively]->(k)")
    void saveNoSimpleKnowledgeLearnShip(@Param("startName") String startName,@Param("endName") String endName);
    /*
    @Query("match (c:material{name:{startName}}) with c match (k:material{name:{endName}})  match(c)-[r]->(k) delete r")
    void delNoSimpleKnowledgeLearnShip(@Param("startName") String startName,@Param("endName") String endName);*/


}
